package com.springboot.springbootweb.controller;

import com.springboot.springbootweb.Bean.Person2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    Person2 person2;

    @GetMapping("home")
    public String index(Model model) {
        String username = "happy day!";
        String title = "thymeleaf!";
        Map<String, String> maps = new HashMap<>();
        maps.put("1", "o");
        maps.put("2", "g");
        maps.put("3", "a");
        maps.put("4", "j");
        List<String> lists = new ArrayList<>();
        lists.add("100");
        lists.add("200");
        lists.add("300");
        lists.add("400");
        model.addAttribute("person2", person2);
        model.addAttribute("lists", lists);
        model.addAttribute("maps", maps);
        model.addAttribute("title", title);
        model.addAttribute("username", username);
        return "index";
    }

    @RequestMapping("vuetest")
    public String vuetest(Model model) {
        return "vue/vuetest";
    }

    @GetMapping("/admin/hello")
    @ResponseBody
    public String hello2(){
        return "admin";
    }
    @GetMapping("/db/hello")
    @ResponseBody
    public String hello3(){
        return "db";
    }
    @GetMapping("/user/hello")
    @ResponseBody
    public String hello4(){
        return "user";
    }
}